# 未完成，怀疑头部 portal-sign 处理问题


import requests

import execjs

import json

import time

cookies = {
    'ASP.NET_SessionId': 'aruvhl5xtpills2ymfv3nv2u',
}

headers = {
    'Accept': 'application/json, text/plain, */*',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Connection': 'keep-alive',
    'Content-Type': 'application/json;charset=UTF-8',
    # 'Cookie': 'ASP.NET_SessionId=aruvhl5xtpills2ymfv3nv2u',
    'Origin': 'https://ggzyfw.fj.gov.cn',
    'Referer': 'https://ggzyfw.fj.gov.cn/business/list/',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36',
    # 'portal-sign': '1bace6fd4776371c1b69578faa390bb4',
    'sec-ch-ua': '"Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}

# for item in range(20):
json_data = {
    'pageNo': 1,
    'pageSize': 20,
    'total': 4404,
    'AREACODE': '',
    'M_PROJECT_TYPE': '',
    'KIND': 'GCJS',
    'GGTYPE': '1',
    'PROTYPE': '',
    'timeType': '6',
    'BeginTime': '2023-05-01 00:00:00',
    'EndTime': '2023-10-31 23:59:59',
    'createTime': [],
}

portal_sign_data = execjs.compile(open("逆向js.js", 'r', encoding="utf-8").read()).call("get_portal_sign")
headers['portal-sign'] = portal_sign_data
json_data = execjs.compile(open("逆向js.js", 'r', encoding="utf-8").read()).call("get_json_data")

response = requests.post('https://ggzyfw.fj.gov.cn/FwPortalApi/Trade/TradeInfo', cookies=cookies, headers=headers, json=json_data).json()

print(response)

if response == 200:
    data = execjs.compile(open("逆向js.js", 'r', encoding="utf-8").read()).call("b", response["Data"])
    json_data = json.loads(data)

    response_data = json_data['Table']
    for index,item in enumerate(response_data):
        print(item["TITLE"] + " - " + item["NAME"])

    time.sleep(10)

